package com.taillive.commons;


public class ConvertUtils {

	/**
	 * 
	 * @param s
	 * @return 
	 */
	public static String trim(String s) {
		if(true){
			
		}
		return s == null ? "" : s.trim();
	}
	
	//---------------------------------------------------------------
	
	/**
	 * boolean to int
	 * @param b
	 * @return
	 */
	public static int b2i(boolean b) {
		return b ? 1 : 0;
	}

	/**
	 * int to boolean
	 * @param i
	 * @return
	 */
	public static boolean i2b(int i) {
		return (i == 1);
	}

	
	//---------------------------------------------------------------
	/**
	 * string to int
	 * @param s
	 * @return int
	 */
	public static int s2i(String s) {
		if (s == null) {
			return 0;
		}
		try {
			return Integer.parseInt(s);
		} catch (Exception e) {
			return 0;
		}
	}

	
	/**
	 * int to string
	 * @param i
	 * @return
	 */
	public static String i2s(int i) {
		return String.valueOf(i);
	}

	
	//---------------------------------------------------------------
	/**
	 * string to long
	 * @param s
	 * @return long
	 */
	public static long s2l(String s) {
		if (s == null) {
			return 0;
		}
		try {
			return Long.parseLong(s);
		} catch (Exception e) {
			return 0;
		}
	}

	
	/**
	 * int to string
	 * @param i
	 * @return
	 */
	public static String l2s(long i) {
		return String.valueOf(i);
	}
	
	//---------------------------------------------------------------
	/**
	 * string to double
	 * @param s
	 * @return
	 */
	public static double s2d(String s) {
		if (s == null) {
			return 0;
		}
		try {
			return Double.parseDouble(s);
		} catch (Exception e) {
			return 0;
		}

	}
	/**
	 * double to string
	 * @param d
	 * @return
	 */
	public static String d2s(double d) {
		return String.valueOf(d);
	}	
	
	
	//---------------------------------------------------------------
	/**
	 * string to float
	 * @param s
	 * @return
	 */
	public static float s2f(String s) {
		if (s == null) {
			return 0;
		}

		try {
			return Float.parseFloat(s);
		} catch (Exception e) {
			return 0;
		}
	}
	
	/**
	 * float to string
	 * @param f
	 * @return
	 */
	public static String f2s(float f) {
		return String.valueOf(f);
	}

}
